#!/bin/bash

path=`cd "$( dirname ${BASH_SOURCE[0]} )" && pwd`
config=$path/config
bin=$path/bin
python_config=$config/python
python=$bin/python

while(true)
do
	clear
	echo "欢迎使用GenshinUID（早柚核心）管理"
	echo ==================================
	echo "1.安装GenshinUID（早柚核心）"
	echo "2.修改配置文件"
	echo "3.更新GenshinUID（早柚核心）管理脚本"
	echo "4.卸载GenshinUID（早柚核心）"
	echo "5.安装驱动器，适配器，插件（未完成）"
    echo "6.后台运行GenshinUID（早柚核心）"
	echo "7.退出"
	echo ==================================
	read -p "请选择：" op
	if [[ $op = "1" ]];then
		clear
		echo "开始安装ubuntu依赖"
		source $bin/rely.sh $config/rely.txt
		tar -xf install_file/gsuid_bot.tar.xz
		echo "开始拉取资源"
		source git_gsbot.sh
		echo "是否安装编译python?"
		read -p "请选择y or n：" py
		if [[ $py = "y" ]];then
			source install_python.sh
		else
			echo "" > $python_config/export.txt
		fi
		echo "安装依赖"
		source install_rely.sh
	elif [[ $op = "2" ]];then
		clear
		echo ==================================
		echo "1.修改.env"
		echo "2.修改.env.prod"
		echo "3.还原默认.env"
		echo "4.还原默认.env.prod"
		echo ==================================
		read -p "请选择：" op
		clear
		if [[ $op = "1" ]];then
			config_file="$path/gsuid_bot/.env"
		elif [[ $op = "2" ]];then
			config_file="$path/gsuid_bot/.env.prod"
		elif [[ $op = "3" ]];then
			cp -f "$path/gsuid_bot/.env.bk" "$path/gsuid_bot/.env"
			continue
		elif [[ $op = "4" ]];then
			cp -f "$path/gsuid_bot/.env.prod.bk" "$path/gsuid_bot/.env.prod"
			continue
		fi
		cat $config_file
		echo ==================================
		echo "请输入需要修改参数名+参数值（空格隔开）"
		echo "例如：HOST（空格）127.0.0.1"
		echo ==================================
		read -p "请输入：" op
		source $bin/config_up.sh $config_file $op
	elif [[ $op = "3" ]];then
		clear
		git pull
	elif [[ $op = "4" ]];then
		clear
		rm -rf gsuid_bot
		rm -rf gsuid_core
	elif [[ $op = "5" ]];then
		clear
		cat "$path/config/driver.txt"
		cat "$path/config/adapter.txt"
		cat "$path/config/plugin.txt"
 		echo ==================================
		echo "参考示例：1（空格）1"
		echo "1.安装驱动器+驱动器序号"
		echo "2.安装适配器+适配器序号"
		echo "3.安装插件+插件序号"
		echo ==================================
		read -p "请选择：" op
		cd gs_bot
		source $bin/nonobot/install.sh $op
		cd $path
	elif [[ $op = "6" ]];then    
        cd ./gsuid_bot
		nohup nb run &
	elif [[ $op = "7" ]];then    
        break
    fi
done



